package com.tanhua.server.controller;

import com.tanhua.dubbo.server.pojo.Test1;
import com.tanhua.server.service.Test1Service;
import com.tanhua.server.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("users")
public class Test1Controller {
    @Autowired
    private Test1Service test1Service;

    @PostMapping("save")
    public ResponseEntity<String> update(@RequestBody Map<String, Boolean> param){
        try {
            Boolean likeOpen = param.get("likeOpen");
            Boolean commentOpen = param.get("commentOpen");
            Boolean announcementOpen = param.get("announcementOpen");
            Boolean save = this.test1Service.update(likeOpen, commentOpen, announcementOpen);
            if(save){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping("find")
    public ResponseEntity<Test1> find(){
        try {
            Test1 test1 = this.test1Service.find();
            if (null!=test1){
                return ResponseEntity.ok(test1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();


    }
}
